package com.asia5b.a5bmall.same.dialog

import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
import com.asia5b.a5bmall.same.R
import com.asia5b.a5mall.middleware.config.CountrysRepository
import com.asia5b.a5bmall.same.adapter.ChoiceCurrencyAdapter
import com.asia5b.a5mall.middleware.model.member.CurrencyModel
import com.asia5b.a5mall.middleware.base.BaseDialog
import com.asia5b.a5mall.middleware.utils.newDivider
import kotlinx.android.synthetic.main.dialog_choicecurrency.*

/**
 * Created by zhangyuncai on 2020/3/28.
 * 选择货币及其对应的价格
 */
class ChoiceCurrencyDialog(context: Context) : BaseDialog(context) {
    override val layoutId: Int=R.layout.dialog_choicecurrency
    override val heightPercent: Double= 0.7


    private val mDatas = arrayListOf<CurrencyModel>()
    var select_currency = CountrysRepository.getCurrencySelect();
    private val mAdapter by lazy {
        ChoiceCurrencyAdapter(mDatas)
    }
    val rv_choicecurrency by lazy { rv_parcel }




    override fun initView() {
        mAdapter.select_currency=select_currency
        rv_choicecurrency.run {
            layoutManager = LinearLayoutManager(context)!!
            adapter = mAdapter
            addItemDecoration(newDivider(context))
        }


        CountrysRepository.anyCallback<ArrayList<CurrencyModel>>({currency_list->
            mDatas.clear()
            mDatas.addAll(currency_list)
            mAdapter.notifyDataSetChanged()
        },CountrysRepository.currency)

        mAdapter.setOnItemClickListener { _, _, position ->
            val bean = mAdapter.getItem(position)!!
            mSureClick?.invoke(bean)
            dismiss()
        }
    }

    override fun initEvent() {
        iv_dialog_close.setOnClickListener {
            mCancelClick?.invoke()
            dismiss()
        }
    }




}